<?php
	class chuyenmucdb
	{
		public function Them($MaChuyenMuc = 0, $TenChuyenMuc = "")
		{
			$sql = "INSERT INTO chuyenmuc(MaChuyenMuc, TenChuyenMuc)
					VALUES($MaChuyenMuc, '$TenChuyenMuc')";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function TonTaiTrongLoaiChuyenMuc($MaChuyenMuc = 0)
		{
			$sql = "SELECT * FROM loaichuyenmuc WHERE 1";
			if($MaChuyenMuc > 0)
				$sql.= " AND MaChuyenMuc = $MaChuyenMuc";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function CapNhat($MaChuyenMuc = 0, $TenChuyenMuc = "")
		{
			$sql = "UPDATE chuyenmuc 
					SET TenChuyenMuc = '$TenChuyenMuc' 
					WHERE MaChuyenMuc = $MaChuyenMuc";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Xoa($MaChuyenMuc = 0)
		{
			$sql = "DELETE FROM chuyenmuc 
					WHERE MaChuyenMuc = $MaChuyenMuc";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function XoaTatCa()
		{
			$sql = "DELETE FROM chuyenmuc";			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach($MaChuyenMuc = 0, $TenChuyenMuc = "")
		{
			$sql = "SELECT * 
					FROM chuyenmuc 
					WHERE 1";
			
			if($MaChuyenMuc > 0)
				$sql .= " AND MaChuyenMuc = $MaChuyenMuc";
				
			if($TenChuyenMuc != "")
				$sql .= " AND TenChuyenMuc = '$TenChuyenMuc'";
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
	}
?>